from graphics import GraphWin,Line,Point
from math import sqrt, cos, sin, pi

# 画圆
def circle(x0,y0, ts,te, r, ε, line):
    # 坐标
    n = int((te-ts)/2*sqrt(0.5*r/ε)) # 段数
    δ = (te-ts)/n
    cosδ = cos(δ); sinδ = sin(δ)
    # 确定端点坐标，画线
    xs = r*cos(ts); ys = r*sin(ts) # 起点
    for i in range(1,n):
        xe = xs*cosδ - ys*sinδ
        ye = ys*cosδ + xs*sinδ
        line((int(xs+x0),int(ys+y0)),(int(xe+x0),int(ye+y0))) # 画直线
        xs = xe; ys = ye
    xe = r*cos(te); ye = r*sin(te) # 终点
    line((int(xs+x0),int(ys+y0)),(int(xe+x0),int(ye+y0)))

# 窗口
win = GraphWin("圆", 600,600)
win.setBackground('#ffffff')
# 绘图
line = lambda ps,pe:Line(Point(*ps), Point(*pe)).draw(win)
circle(300,300, 0,pi, 256, 1, line)

#等待鼠标响应，退出程序
win.getMouse()
win.close()

